package com.agri.controller;

import com.agri.result.Result;
import com.agri.service.PriceTrendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 价格趋势控制器
 * 提供农产品价格趋势的查询和分析接口
 *
 * @author Agri-Fin-Sale Team
 * @since 2025-11-05
 */
@RestController
@RequestMapping("/price/trend")
public class PriceTrendController {
    @Autowired
    private PriceTrendService priceTrendService;

    /**
     * 获取农产品价格趋势
     */
    @GetMapping("/crop/{cropId}")
    public Result<?> getCropPriceTrend(@PathVariable Long cropId,
                                      @RequestParam(required = false) Date startDate,
                                      @RequestParam(required = false) Date endDate) {
        return priceTrendService.getCropPriceTrend(cropId, startDate, endDate);
    }

    /**
     * 获取农产品最新价格
     */
    @GetMapping("/crop/{cropId}/latest")
    public Result<?> getLatestPrice(@PathVariable Long cropId) {
        return priceTrendService.getLatestPrice(cropId);
    }

    /**
     * 价格预测分析
     */
    @GetMapping("/crop/{cropId}/predict")
    public Result<?> predictPrice(@PathVariable Long cropId) {
        return priceTrendService.predictPrice(cropId);
    }
}